home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / infobox / htmlgeneration.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  10KB  |  365 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from time import time
  6. from xml.sax.saxutils import escape
  7. from gui.textutil import default_font
  8. from util import Point2HTMLSize, linkify
  9. from gui.skin import get as skin_get
  10. separatorshort = u'<br><wxp module="gui.infobox.htmlbitmaps" class="BitmapFromSkin" width="99%" height="-1"><param name="key" value="infobox.shortseparatorimage"><param name="padding" value="(3,3)"></wxp>'
  11. separatorlong = u'<br><wxp module="gui.infobox.htmlbitmaps" class="BitmapFromSkin" width="100%" height="-1"><param name="key" value="infobox.longseparatorimage"><param name="padding" value="(0,4)"></wxp>'
  12. JABBER_SERVICES = [
  13.     u'jabber',
  14.     u'gtalk',
  15.     u'digsby']
  16. from common.protocolmeta import protocols
  17. titlespace = u' '
  18.  
  19. def ColorHTML(color):
  20.     if color[0:2].lower() == '0x':
  21.         return ''.join('#', color[2:8])
  22.     
  23.     return color
  24.  
  25.  
  26. def GenBitmapHTML(key, width, height):
  27.     return u''.join([
  28.         u'<wxp module="gui.infobox.htmlbitmaps" class="BitmapFromSkin" width ="',
  29.         str(width),
  30.         u'" height="',
  31.         str(height),
  32.         u'"><param name="key" value="',
  33.         key,
  34.         u'"></wxp>'])
  35.  
  36.  
  37. def GenBuddyIconHTML(contid):
  38.     return u''.join([
  39.         u'<wxp module="gui.infobox.htmlbitmaps" class="BuddyIcon"><param name="contid" value="',
  40.         contid,
  41.         u'"></wxp>'])
  42.  
  43.  
  44. def FontTagify(string, fonttype):
  45.     font = skin_get('infobox.fonts.%s' % fonttype, default_font())
  46.     color = skin_get('infobox.fontcolors.%s' % fonttype, wx.BLACK).GetAsString(wx.C2S_HTML_SYNTAX)
  47.     if isinstance(string, str):
  48.         
  49.         try:
  50.             string = string.decode('fuzzy')
  51.         except UnicodeDecodeError:
  52.             e = None
  53.             log.info("Couldn't put %r into a font tag- decode failed with error %r", string, e)
  54.             return ''
  55.         except:
  56.             None<EXCEPTION MATCH>UnicodeDecodeError
  57.         
  58.  
  59.     None<EXCEPTION MATCH>UnicodeDecodeError
  60.     tag = None([
  61.         None,
  62.         None,
  63.         None,
  64.         None,
  65.         None,
  66.         u''.join,
  67.         '<font face="',
  68.         font.FaceName,
  69.         '" size="',
  70.         str(Point2HTMLSize(font.PointSize)),
  71.         '" color="',
  72.         color,
  73.         '">' if font.Weight == wx.BOLD else '' if font.Style == wx.ITALIC else '' if font.Underlined else '',
  74.         string if font.Underlined else '' if font.Style == wx.ITALIC else '' if font.Weight == wx.BOLD else '',
  75.         '</font>'])
  76.     return tag
  77.  
  78.  
  79. def TitleHTML(title):
  80.     return FontTagify(escape(title).replace('\n', '<br>'), 'title')
  81.  
  82.  
  83. def BodyHTML(text):
  84.     return FontTagify(escape(text).replace('\n', '<br>'), 'minor')
  85.  
  86.  
  87. def List2HTML(listostuff):
  88.     string = ''
  89.     for stuff in listostuff:
  90.         if isinstance(stuff, basestring):
  91.             pass
  92.         elif isinstance(stuff, tuple):
  93.             pass
  94.         elif isinstance(stuff, list):
  95.             pass
  96.         elif isinstance(stuff, dict):
  97.             pass
  98.         
  99.         string = ''.join([
  100.             string,
  101.             ''])
  102.     
  103.     return string
  104.  
  105.  
  106. def ListProfile2HTML(listostuff):
  107.     profile = []
  108.     for stuff in listostuff:
  109.         if isinstance(stuff, basestring):
  110.             pass
  111.         elif isinstance(stuff, dict):
  112.             pass
  113.         
  114.         profile.append('')
  115.     
  116.     return ''.join(profile)
  117.  
  118.  
  119. def PrettyProfile2HTML(profile):
  120.     if not profile:
  121.         return 'No Profile'
  122.     
  123.     string = ''
  124.     for key in profile.keys():
  125.         value = profile[key]
  126.         if value:
  127.             if isinstance(value, int):
  128.                 string = ''.join([
  129.                     string,
  130.                     exbr(value)])
  131.             elif isinstance(value, basestring):
  132.                 pass
  133.             elif isinstance(value, tuple):
  134.                 pass
  135.             elif isinstance(value, list):
  136.                 pass
  137.             elif isinstance(value, dict):
  138.                 pass
  139.             
  140.             string = ''.join([
  141.                 string,
  142.                 TitleHTML(key),
  143.                 titlespace,
  144.                 '',
  145.                 '<br>'])
  146.             continue
  147.     
  148.     return string
  149.  
  150.  
  151. def exbr(height):
  152.     return ''.join([
  153.         '<table cellpadding=',
  154.         str(height),
  155.         ' cellspacing=0 border=0><tr><td></td></tr></table>'])
  156.  
  157.  
  158. def ProfileHTML(profile):
  159.     if isinstance(profile, dict):
  160.         profile = PrettyProfile2HTML(profile)
  161.     elif isinstance(profile, list):
  162.         profile = ListProfile2HTML(profile)
  163.     else:
  164.         profile = u'<TABLE width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>No Profile</td></tr></table>'
  165.     return u''.join([
  166.         u'</TD></TR></TABLE>',
  167.         u'<TABLE WIDTH=100% cellpadding=0 border=0><TR><TD>',
  168.         separatorlong,
  169.         profile])
  170.  
  171.  
  172. def ImageHTML(**attrs):
  173.     if not attrs:
  174.         return ''
  175.     
  176.     if 'src' in attrs:
  177.         key = 'url'
  178.         cls = 'BitmapFromWeb'
  179.         data = attrs['src']
  180.     elif 'data' in attrs:
  181.         key = 'data'
  182.         cls = 'BitmapFromData'
  183.         b64encode = b64encode
  184.         import base64
  185.         data = b64encode(attrs['data'])
  186.     
  187.     w = attrs.get('width', -1)
  188.     h = attrs.get('height', -1)
  189.     href = attrs['href']
  190.     return '<wxp module="gui.infobox.htmlbitmaps" class="%(cls)s" width="%(w)d" height="%(h)d"><param name="%(key)s" value="%(data)s"><param name="href" value="%(href)s"></wxp>' % locals()
  191.  
  192.  
  193. def LinkHTML(url, text):
  194.     if isinstance(text, basestring):
  195.         pass
  196.     elif isinstance(text, dict):
  197.         pass
  198.     
  199.     return u''.join([
  200.         u'<a href=',
  201.         url,
  202.         u'>',
  203.         FontTagify('', 'link'),
  204.         u'</a>'])
  205.  
  206.  
  207. def GenTimedString(timeinsecs):
  208.     secs = int(time()) - timeinsecs
  209.     (mins, secs) = divmod(secs, 60)
  210.     (hours, mins) = divmod(mins, 60)
  211.     (days, hours) = divmod(hours, 24)
  212.     if not days > 0 and hours > 0 or mins > 0:
  213.         return u'<1m'
  214.     
  215.     timeStr = u''
  216.     if days > 0:
  217.         timeStr += str(int(days)) + u'd '
  218.     
  219.     if hours > 0:
  220.         timeStr += str(int(hours)) + u'h '
  221.     
  222.     if mins > 0:
  223.         timeStr += str(int(mins)) + u'm'
  224.     
  225.     return timeStr
  226.  
  227.  
  228. def JabberStatusMagic(contact):
  229.     string = u''.join([
  230.         TitleHTML(u'Subscription:'),
  231.         titlespace,
  232.         BodyHTML(contact.protocol.roster.get_item_by_jid(contact.id).subscription.capitalize())])
  233.     for r in contact.resources.values():
  234.         if not r.jid.resource:
  235.             pass
  236.         string = u''.join([
  237.             string,
  238.             separatorshort,
  239.             TitleHTML(u'Resource:'),
  240.             titlespace,
  241.             BodyHTML(u''.join([
  242.                 '',
  243.                 u' (',
  244.                 str(r.priority),
  245.                 u')']))])
  246.         string = u''.join([
  247.             string,
  248.             u'<br>',
  249.             TitleHTML(u'Status:'),
  250.             titlespace,
  251.             BodyHTML(r.sightly_status)])
  252.         if r.status_message:
  253.             string = u''.join([
  254.                 string,
  255.                 u'<br>',
  256.                 BodyHTML(r.status_message)])
  257.             continue
  258.     
  259.     return string
  260.  
  261.  
  262. def GetInfo(contact, showprofile = False, showhide = True):
  263.     wx.GetApp().StupidContactHack = contact
  264.     constanttop = u''.join([
  265.         u'<body><TABLE WIDTH=100% cellpadding=0 border=0><TR><TD valign=top>'])
  266.     constantmiddle = u'</TD><TD width=64 valign=top align=center>'
  267.     constantbottom = u'</TD></TR></TABLE></body>'
  268.     s = contact.service
  269.     if s == 'digsby' and getattr(contact, 'iswidget', False):
  270.         s = 'widget'
  271.     
  272.     servico = u''.join([
  273.         u'<TABLE WIDTH=100% cellpadding=0 cellspacing=0 border=0 VALIGN=CENTER ALIGN=LEFT><TR><TD valign=center>',
  274.         GenBitmapHTML(u'serviceicons.' + s, 16, 16),
  275.         u'</TD><TD> </TD>'])
  276.     displayname = contact.alias
  277.     name = u''.join([
  278.         u'<TD WIDTH=100%>',
  279.         FontTagify(escape(displayname), 'header'),
  280.         u'</TD></TR></TABLE><TABLE WIDTH=100% cellpadding=1 cellspacing=0 border=0><TD></TD></TABLE>'])
  281.     if s == 'widget':
  282.         ip = u''.join([
  283.             TitleHTML(u'IP Address:'),
  284.             titlespace,
  285.             BodyHTML(contact.ip)])
  286.         time = u''.join([
  287.             TitleHTML(u'Time on Page:'),
  288.             titlespace,
  289.             BodyHTML(GenTimedString(contact.online_time))])
  290.         html = u''.join([
  291.             constanttop,
  292.             servico,
  293.             name,
  294.             u'<br>',
  295.             ip,
  296.             u'<br>',
  297.             time,
  298.             constantbottom])
  299.         return html
  300.     
  301.     username = contact.nice_name
  302.     if username != displayname:
  303.         name = u''.join([
  304.             name,
  305.             '<br>',
  306.             TitleHTML(protocols[contact.service].username_desc) + u':',
  307.             titlespace,
  308.             BodyHTML(username)])
  309.     
  310.     profile = None if showprofile else u''
  311.     if contact.service in ('icq', 'aim') and contact.online_time:
  312.         times = u''.join([
  313.             TitleHTML(u'Online:'),
  314.             titlespace,
  315.             BodyHTML(GenTimedString(contact.online_time))])
  316.     else:
  317.         times = u''
  318.     if contact.service in ('icq', 'aim', 'yahoo'):
  319.         if contact.idle and contact.idle is not True:
  320.             pass
  321.         elif times:
  322.             pass
  323.         
  324.         times = None([
  325.             u''.join,
  326.             u''])
  327.     
  328.     if contact.status_orb == 'unknown' or contact.service not in JABBER_SERVICES:
  329.         status = u''.join([
  330.             TitleHTML(u'Status:'),
  331.             titlespace,
  332.             BodyHTML(contact.sightly_status)])
  333.     else:
  334.         status = JabberStatusMagic(contact)
  335.     if contact.status == u'away' and contact.idle:
  336.         status = u''.join([
  337.             status,
  338.             BodyHTML(u' + Idle')])
  339.     
  340.     statusmsg = getattr(contact, '_infobox_status_message', contact.status_message)
  341.     if not statusmsg or contact.service in JABBER_SERVICES:
  342.         statusmsg = ''
  343.     elif contact.service not in ('aim', 'icq'):
  344.         statusmsg = BodyHTML(statusmsg)
  345.     
  346.     statusmsg = u''.join((separatorshort, statusmsg))
  347.     icon = None([
  348.         None,
  349.         ''.join,
  350.         constantmiddle,
  351.         GenBuddyIconHTML(contact.idstr())(u'<br><table cellpadding="1" cellspacing="0" border="0"><tr><td></td></tr></table>', LinkHTML if showhide else '')])
  352.     html = u''.join([
  353.         constanttop,
  354.         servico,
  355.         name,
  356.         u'<br>',
  357.         times,
  358.         status,
  359.         statusmsg,
  360.         icon,
  361.         profile,
  362.         constantbottom])
  363.     return linkify(html)
  364.  
  365.